﻿using System;

namespace Co9320.NamaAlert.Engine.Feeder.Util
{
	internal static class Util
	{
		private const long ConversionParameter = 10000000L;
		private static readonly long TheEpoch = new DateTime(1970, 1, 1, 9, 0, 0, DateTimeKind.Local).Ticks / ConversionParameter;
		private const long RoundParameter = 18000000000L;
		private static readonly TimeSpan FrameSpan = new TimeSpan(0, 30, 0);


		public static DateTime ToDateTime(this long UnixTime)
		{
			long Ticks = 0;
			Ticks = TheEpoch + UnixTime;
			Ticks *= ConversionParameter;
			return new DateTime(Ticks, DateTimeKind.Local);
		}

		public static DateTime Round(this DateTime Target)
		{
			return new DateTime((Target.Ticks / RoundParameter) * RoundParameter);
		}

		public static DateTime NextFrameStart(this DateTime Target)
		{
			return Target.Round() + FrameSpan;
		}

		public static long ToUnixTime(this DateTime time)
		{
			long Ticks = time.Ticks / ConversionParameter;
			Ticks -= TheEpoch;
			return Ticks;
		}
	}
}
